package comms;

import java.net.InetAddress;

import Vis.DevicePanel;
import Vis.Visualiser;

public class Device {

	private InetAddress ipaddress;
	private int port;
	private Visualiser v;
	private DevicePanel uiPanel;
	private boolean isConnected = false;
	
	public Device(InetAddress ip, int p, String name, Visualiser vis){
		ipaddress = ip;
		port = p;
		v = vis;
		
		uiPanel = new DevicePanel(this, name, true, false);
		v.addDevice(uiPanel);
		
	}
	
	public Device(InetAddress ip, int port, Visualiser v){
		this(ip, port, ip.toString(), v);
	}
	
	public void setName(String s){
		uiPanel.setName(s);
		uiPanel.validate();

	}
	
	public InetAddress getIPAddress(){
		return ipaddress;
	}
	
	public int getPort(){
		return port;
	}
	
	public void disconnect(){	
		if(uiPanel!=null)
			v.removeDevice(uiPanel);
		v.validate();
	}
	
	public DevicePanel panel(){
		return uiPanel;
	}
	
	public void setConnected(){
		isConnected = true;
	}
	
	public boolean isConnected(){
		return isConnected;
	}
}
